package com.meida.module.bus.provider.controller;

import com.meida.common.utils.StringUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import com.meida.common.mybatis.model.*;

import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RestController;
import com.meida.common.springmvc.base.BaseController;
import com.meida.module.bus.client.entity.BusMajor;
import com.meida.module.bus.provider.service.BusMajorService;


/**
 * 专业表控制器
 *
 * @author flyme
 * @date 2020-12-16
 */
@RestController
@RequestMapping("/bus/major/")
public class BusMajorController extends BaseController<BusMajorService, BusMajor> {

    @ApiOperation(value = "专业表-分页列表", notes = "专业表分页列表")
    @GetMapping(value = "page")
    public ResultBody pageList(@RequestParam(required = false) Map params) {
        return bizService.pageList(params);
    }

    @ApiOperation(value = "专业表-列表", notes = "专业表列表")
    @GetMapping(value = "list")
    public ResultBody list(@RequestParam(required = false) Map params) {
        return bizService.listEntityMap(params);
    }

    @ApiOperation(value = "专业表-添加", notes = "添加专业表")
    @PostMapping(value = "save")
    public ResultBody save(@RequestParam(required = false) Map params) {
        return bizService.add(params);
    }

    @ApiOperation(value = "专业表-更新", notes = "更新专业表")
    @PostMapping(value = "update")
    public ResultBody update(@RequestParam(required = false) Map params) {
        return bizService.edit(params);
    }

    @ApiOperation(value = "专业表-删除", notes = "删除专业表")
    @PostMapping(value = "remove")
    public ResultBody remove(@RequestParam(required = false) Map params) {
        return bizService.delete(params);
    }


    @ApiOperation(value = "专业表-详情", notes = "专业表详情")
    @GetMapping(value = "get")
    public ResultBody get(@RequestParam(required = false) Map params) {
        return bizService.get(params);
    }

    @ApiOperation(value = "用户分配专业", notes = "用户分配专业")
    @PostMapping("/setMajor")
    public ResultBody addUserMajors(
        @RequestParam(value = "userId") Long userId,
        @RequestParam(value = "majorIds", required = false) String majorIds
    ) {
        bizService.saveUserMajors(userId, StringUtils.isNotBlank(majorIds) ? majorIds.split(",") : new String[]{});
        return ResultBody.msg("设置成功");
    }

}
